<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        // 第一种定义对象的方式
        /* var dog = new Object()
        dog.name = "小黄"
        var person = new Object()
        person.name = "张三"
        person.age = 23
        person.dog = dog
        person.hobbies = ["足球", "乒乓球", "羽毛球"]
        console.log(person)
        var personStr = JSON.stringify(person)
        console.log(personStr) */

        // 第二种定义对象的方式
        /* var dog = {
            name: "小黄"
        }
        var person = {
            name: "张三",
            age: 23,
            "dog": dog,
            "hobbies": ["足球", "乒乓球", "羽毛球"]
        }
        console.log(person)
        var personStr = JSON.stringify(person)
        console.log(personStr) */

        var str = '{"name":"张三","age":23,"dog":{"name":"小黄"},"hobbies":["足球","乒乓球","羽毛球"]}'
        var person = JSON.parse(str)
        console.log(str)
        console.log(person)

    </script>
</head>
<body>
    
</body>
</html>